package com.wangshuqi.spring.dao.impl;

import com.wangshuqi.spring.dao.AccountDAO;
import com.wangshuqi.spring.entity.Account;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class AccountDAOImpl implements AccountDAO {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public int addMoney(Account account) {
        String sql = "update account set money=money + ? where name = ?";
        return jdbcTemplate.update(sql, account.getMoney(), account.getName());
    }

    @Override
    public int reduceMoney(Account account) {
        String sql = "update account set money=money - ? where name = ?";
        return jdbcTemplate.update(sql, account.getMoney(), account.getName());
    }
}
